<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\erp\home;

use app\common\controller\AuthCheck;

/**
 * 采购单入库
 * @package app\erp\home
 */
class PurchaseWarehousing extends AuthCheck
{
    /**
     * 采购入库单列表
     * @author shiqiang
     * @return mixed
     */
    public function list(){
		//参数接收
        $params 		= $this->getParams(0);//0 get 1 post 
        $user_id    	= intval(isset($params["user_id"]) ? $params["user_id"] : 0);
		
		/*******搜索条件*********/
		$handled_by 	= isset($params["handled_by"]) ? $params["handled_by"] : ''; 
		$code 			= isset($params["code"]) ? $params["code"] : ''; 
        /*******搜索条件*********/
		
        //数据验证
        $Validate = validate('PurchaseWarehousing', 'validate');
        if( !$Validate -> scene('purchase_list') -> check($params) ){
            json_out(-1001, $Validate -> getError(), []);//验证失败
        }

        //逻辑处理
        $list = controller('PurchaseWarehousinglogic', 'logic') -> list($user_id, $handled_by, $code);

        //数据返回
        json_out($list['code'], $list['message'], $list['data']);        
    }

    /**
     * 申请入库
     * @author shiqiang
     * @return mixed
     */
    public function add(){
		//参数接收
        $params = $this->getParams(1);//0 get 1 post 
		/* $params['order_sku'] = [ //参数
            [
                'purchase_sku_id' 	=> 1,
                'sku_id' 			=> 18,
                'rk_num' 			=> 10,
                'remark' 			=> '备注备注1',
            ],
            [
				'purchase_sku_id' 	=> 2,
				'sku_id' 			=> 19,
                'rk_num' 			=> 15,
                'remark' 			=> '备注备注2',
            ],
        ]; */

        //测试参数
        $user_id     = intval(isset($params["user_id"]) ? $params["user_id"] : 0);;
        $order_id    = intval(isset($params["order_id"]) ? $params["order_id"] : 0);
        $handled_by	 = isset($params["handled_by"]) ? $params["handled_by"] : '';
        $remark      = isset($params["remark"]) ? $params["remark"] : '';
        $order_sku   = isset($params["order_sku"]) ? $params["order_sku"] : [];
        
        //数据验证
        $Validate = validate('PurchaseWarehousing', 'validate');
        if( !$Validate -> scene('purchase_add') -> check($params) ){
            json_out(-1001, $Validate -> getError());//验证失败
        }
        
        //逻辑处理
        $list = controller('PurchaseWarehousinglogic', 'logic') -> add($user_id,$order_id, $handled_by, $remark, $order_sku);

        //数据返回
        json_out($list['code'], $list['message']);        
    }
	
	 /**
     * 入库单详情
     * @author shiqiang
     * @return mixed
     */
    public function details(){
		//参数接收
        $params 		= $this->getParams(0);//0 get 1 post 
        $user_id    	= intval(isset($params["user_id"]) ? $params["user_id"] : 0);
        $id    			= intval(isset($params["id"]) ? $params["id"] : 0);
		
        //数据验证
        $Validate = validate('PurchaseWarehousing', 'validate');
        if( !$Validate -> scene('purchase_details') -> check($params) ){
            json_out(-1001, $Validate -> getError(), []);//验证失败
        }

        //逻辑处理
        $list = controller('PurchaseWarehousinglogic', 'logic') -> details($user_id, $id);

        //数据返回
        json_out($list['code'], $list['message'], (object)$list['data']);        
    }
}

